﻿using System;
using System.Net;
using System.Windows;
using System.Collections;
using System.Collections.Generic;
using Windows.UI.Xaml.Markup;
using Windows.Foundation;

namespace BlueRoseGames.Controls.Text
{
    [ContentProperty(Name="Children")]
    public class TransformGroup : Transform
    {
        TransformCollection children = new TransformCollection();
        bool _isDirty = false;
        public TransformGroup()
        {
            children.CollectionChanged += children_CollectionChanged;
        }

        void children_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            _isDirty = true;
        }

        public override Point TransformPoint(Point p)
        {
            Point ret = p;
            foreach (Transform t in children)
            {
                if (!t.GetDisabledState())
                    ret = t.TransformPoint(ret);
            }
            return ret;
        }

        public TransformCollection Children
        {
            get
            {
                return children;
            }
        }

        public override bool Changed
        {
            get
            {
                if (_isDirty) return true;
                foreach (Transform t in children)
                {
                    if (t.Changed)
                    {
                        return true;
                    }
                }
                return false;
            }
            set
            {
                _isDirty = value;
                foreach (Transform t in children)
                {
                    t.Changed = value;
                }
            }
        }

    }
}
